package com.king.framework.base.domain.vo;

import java.util.Map;

import com.king.common.utils.ServletUtils;
import com.king.common.utils.text.Convert;

/**
 * 表格数据处理
 * 
 * @author king
 */
public class TableSupport {
	/**
	 * 当前记录起始索引
	 */
	public static final String PAGE_NUM = "pageNum";

	/**
	 * 每页显示记录数
	 */
	public static final String PAGE_SIZE = "pageSize";

	/**
	 * 排序列
	 */
	public static final String ORDER_BY_COLUMN = "sorts";
	

	/**
	 * 排序的分隔符,如  ts@asc
	 */
	public static final String ORDER_SPLIT = "@";

	/**
	 * 排序的方向 "desc" 或者 "asc".
	 */
	public static final String IS_ASC = "isAsc";

	/**
	 * 分页参数合理化
	 */
	public static final String REASONABLE = "reasonable";


	public static PageDomain buildPageRequest() {
		PageDomain pageDomain = new PageDomain();
		pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1));
		pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10));
		pageDomain.setSorts(ServletUtils.getParameter(ORDER_BY_COLUMN));
//		pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
		pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
		return pageDomain;
	}

	public static PageDomain buildPageRequest(Map<String, Object> searchMap) {
		PageDomain pageDomain = new PageDomain();
		pageDomain.setPageNum(Convert.toInt(searchMap.get(PAGE_NUM), 1));
		pageDomain.setPageSize(Convert.toInt(searchMap.get(PAGE_SIZE), 10));
		pageDomain.setSorts(Convert.toStr(searchMap.get(ORDER_BY_COLUMN), ""));
//		pageDomain.setIsAsc(Convert.toStr(searchMap.get(IS_ASC), ""));
		pageDomain.setReasonable(Convert.toBool(searchMap.get(REASONABLE)));
		return pageDomain;
	}
}
